<template>
  <div class="auditprocess">
    <div class="auditprocess_1">
      <el-button class="btn" type="primary" plain @click="processimg">流程图</el-button>
      <span class="auditprocess_1_title">实施方案电子流</span>
      <img src="../../assets/images/fanhui.png" @click="back">

    </div>
    <div class="auditprocess_2">
      <el-collapse v-model="activeNames">
        <el-collapse-item name="2" v-if="EmbodimentListTime">
          <template slot="title">
            <div class="collapseTitle">1.0设计方案原资料</div>
            <div class="collapseTime">{{EmbodimentListTime}}</div>
          </template>
          <el-card class="cardBox">
            <EmbodimentList :embodimentListId="embodimentListId" :statusEmbodiment="statusEmbodiment" @getType="cmdGetType" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="3" v-if="DrawingTime || statusDrawing" :class="activeNames[0] == '3'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">2.0负责图纸修改</div>
            <div class="collapseTime">{{DrawingTime}}</div>
          </template>
          <el-card class="cardBox">
            <Drawing :drawingId="drawingId" :nodeIdId="nodeIdId" :statusDrawing="statusDrawing" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="4" v-if="CheckTime || statusCheck" :class="activeNames[0] == '4'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">3.0负责审核</div>
            <div class="collapseTime">{{CheckTime}}</div>
          </template>
          <el-card class="cardBox">
            <Check :statusCheck="statusCheck" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="5" v-if="BudgetTime || statusBudget" :class="activeNames[0] == '5'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">4.0负责预算</div>
            <div class="collapseTime">{{BudgetTime}}</div>
          </template>
          <el-card class="cardBox">
            <Budget :statusBudget="statusBudget" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="6" v-if="ParameterTime || statusParameter" :class="activeNames[0] == '6'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">5.0负责参数表</div>
            <div class="collapseTime">{{ParameterTime}}</div>
          </template>
          <el-card class="cardBox">
            <Parameter :statusParameter="statusParameter" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="7" v-if="ImplementationTime || statusImplementation" :class="activeNames[0] == '7'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">6.0负责实施方案</div>
            <div class="collapseTime">{{ImplementationTime}}</div>
          </template>
          <el-card class="cardBox">
            <Implementation :statusImplementation="statusImplementation" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="8" v-if="DrawingPDFTime || statusDrawingPDF" :class="activeNames[0] == '8'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">7.0图纸导PDF</div>
            <div class="collapseTime">{{DrawingPDFTime}}</div>
          </template>
          <el-card class="cardBox">
            <DrawingPDF :statusDrawingPDF="statusDrawingPDF" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="9" v-if="BudgetPDFTime || statusBudgetPDF" :class="activeNames[0] == '9'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">8.0预算导PDF</div>
            <div class="collapseTime">{{BudgetPDFTime}}</div>
          </template>
          <el-card class="cardBox">
            <BudgetPDF :statusBudgetPDF="statusBudgetPDF" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="10" v-if="ParameterPDFTime || statusParameterPDF" :class="activeNames[0] == '10'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">9.0参数表导PDF</div>
            <div class="collapseTime">{{ParameterPDFTime}}</div>
          </template>
          <el-card class="cardBox">
            <ParameterPDF :statusParameterPDF="statusParameterPDF" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="11" v-if="CombineTime || statusCombine" :class="activeNames[0] == '11'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">10.0合并完整方案</div>
            <div class="collapseTime">{{CombineTime}}</div>
          </template>
          <el-card class="cardBox">
            <Combine :statusCombine="statusCombine" />
          </el-card>
        </el-collapse-item>

        <el-collapse-item name="12" v-if="PrintTime || statusPrint" :class="activeNames[0] == '12'? 'cmdElCollapse': ''">
          <template slot="title">
            <div class="collapseTitle">11.0打印方案</div>
            <div class="collapseTime">{{PrintTime}}</div>
          </template>
          <el-card class="cardBox">
            <Print :statusPrint="statusPrint" />
          </el-card>
        </el-collapse-item>

      </el-collapse>
    </div>
    <ProcessImg :show="showDialog" :nodeId="nodeId" @closeDlg="closeDialog"></ProcessImg>
  </div>
</template>
<script>
import { sysSelectNodesInfo, getAuditFlowDetails } from '@/api/api'
import { mapGetters } from 'vuex'
import budget from '../audit/flow/budget'
import drawing from '../audit/flow/drawing'
import Implementation from '../audit/flow/Implementation'
import parameter from '../audit/flow/parameter'
import check from '../audit/flow/check'
import embodimentList from "../audit/flow/embodimentList";
import DrawingPDF from '../audit/flow/drawing-pdf'
import BudgetPDF from '../audit/flow/budget-pdf'
import ParameterPDF from '../audit/flow/parameter-pdf'
import Combine from '../audit/flow/combine'
import Print from '../audit/flow/print'
import ProcessImg from './processImg'
export default {
  components: {
    Check: check,
    Budget: budget,
    Drawing: drawing,
    Implementation: Implementation,
    Parameter: parameter,
    EmbodimentList: embodimentList,
    DrawingPDF: DrawingPDF,
    BudgetPDF: BudgetPDF,
    ParameterPDF: ParameterPDF,
    Combine: Combine,
    Print: Print,
    ProcessImg
  },
  data () {
    return {
      embodimentListId: '',
      drawingId: '',
      //
      nodeIdId: 2,
      activeNames: ['2'],
      isEdit: false,
      status: '',
      type: '',
      nodeTowardsInfo: '',
      nextNodeID: '',
      // 时间
      EmbodimentListTime: '',
      DrawingTime: '',
      CheckTime: '',
      BudgetTime: '',
      ParameterTime: '',
      ImplementationTime: '',
      DrawingPDFTime: '',
      BudgetPDFTime: '',
      ParameterPDFTime: '',
      CombineTime: '',
      PrintTime: '',
      // 打开审核点击的节点，且作为表单填写或只读样式的判断
      nodeId: '',
      statusEmbodiment: true,
      statusDrawing: false,
      statusCheck: false,
      statusBudget: false,
      statusParameter: false,
      statusImplementation: false,
      statusDrawingPDF: false,
      statusBudgetPDF: false,
      statusParameterPDF: false,
      statusCombine: false,
      statusPrint: false,
      //
      showDialog: false
    }
  },
  computed: {
    ...mapGetters(['jobAccount'])
  },
  created () {
    this.getIds()
  },
  mounted () {
    this.getDatas()
  },
  methods: {
    getIds () {
      this.embodimentListId = this.$route.query.orunid
      this.drawingId = this.$route.query.orunid
      this.nodeIdId = this.$route.query.nodeIdId
      this.activeNames = this.$route.query.activeNames
      this.nodeId = this.$route.query.nodeId
      this.isEdit = this.$route.query.edit
      this.status = this.$route.query.status
      this.preNodeId = this.$route.query.preNodeId
      this.curAuthor = this.$route.query.curAuthor
      // console.log(this.status)
    },
    // 加载数据
    async getDatas () {
      await this.getSelectNodesInfo()
    },
    // 查询指定流程所有节点记录
    async getSelectNodesInfo () {
      await this.getNextAuthor()
      let params = {
        orunid: this.$route.query.orunid
      }
      sysSelectNodesInfo(params).then(res => {
        // console.log(res)
        if (res.code == 200) {
          let infoList = res.data
          if (infoList.length > 0) {
            infoList.forEach(item => {
              if (item.currentNodeID === 'T10002') {
                this.EmbodimentListTime = item.subTime
              }
              if (item.currentNodeID === 'T10003') {
                this.DrawingTime = item.subTime
              }
              if (item.currentNodeID === 'T10004') {
                this.CheckTime = item.subTime
              }
              if (item.currentNodeID === 'T10005') {
                this.BudgetTime = item.subTime
              }
              if (item.currentNodeID === 'T10006') {
                this.ParameterTime = item.subTime
              }
              if (item.currentNodeID === 'T10007') {
                this.ImplementationTime = item.subTime
              }
              if (item.currentNodeID === 'T10008') {
                this.DrawingPDFTime = item.subTime
              }
              if (item.currentNodeID === 'T10009') {
                this.BudgetPDFTime = item.subTime
              }
              if (item.currentNodeID === 'T10010') {
                this.ParameterPDFTime = item.subTime
              }
              if (item.currentNodeID === 'T10011') {
                this.CombineTime = item.subTime
              }
              if (item.currentNodeID === 'T10012') {
                this.PrintTime = item.subTime
              }
            })
          }
        }
      }).then(() => {
        // 显示点击的节点
        if (this.isEdit) {
          // console.log(this.nodeId)
          // nodeId
          if (this.nodeId === 'T10002') {
            this.statusEmbodiment = false
          }
          if (this.nodeId === 'T10003') {
            this.statusDrawing = true
          }
          if (this.nodeId === 'T10004') {
            this.statusCheck = true
          }
          if (this.nodeId === 'T10005') {
            this.statusBudget = true
          }
          if (this.nodeId === 'T10006') {
            this.statusParameter = true
          }
          if (this.nodeId === 'T10007') {
            this.statusImplementation = true
          }
          if (this.nodeId === 'T10008') {
            this.statusDrawingPDF = true
          }
          if (this.nodeId === 'T10009') {
            this.statusBudgetPDF = true
          }
          if (this.nodeId === 'T10010') {
            this.statusParameterPDF = true
          }
          if (this.nodeId === 'T10011') {
            this.statusCombine = true
          }
          if (this.nodeId === 'T10012') {
            this.statusPrint = true
          }
        }
      }).catch((err) => { })
    },
    // 先再调一次流程数据  // 待定
    async getNextAuthor () {
      let params = {
        orunid: this.$route.query.orunid
      }
      await getAuditFlowDetails(params).then(res => {
        // console.log(res)
        if (res.code == 200) {
          // 获取nodeTowardsInfo，用里面的preNodeID与传来的nodeId匹配，然后找到currentAuthor与当前jobAccount对比，来判断是否有权限编辑
          // this.nodeTowardsInfo = res.data.nodeTowardsInfo
          // this.nextNodeID = res.data.nextNodeID
        } else {
          swal('错误', res.message || '网络连接错误', 'warning')
        }
      }).catch((err) => {
        swal('错误', '获取数据失败', 'error')
      })
    },
    back () {
      this.$router.go(-1)
    },
    processimg () {
      // console.log(this.CheckTime)
      this.nodeId = this.$route.query.nodeId
      this.showDialog = true
    },
    closeDialog () {
      this.showDialog = false
    },
    cmdGetType (event) {

    }
  }
}
</script>
<style lang="less" scoped>
.auditprocess {
  /* background: rgba(236, 240, 245); */
  width: 75%;
  height: 100%;
  margin: 15px auto;
  .auditprocess_1 {
    width: 100%;
    height: 40px;
    // background: red;
    line-height: 40px;
    text-align: center;
    .auditprocess_1_title {
      font-weight: bold;
      font-size: 30px;
    }
    img {
      margin-top: 10px;
      width: 25px;
      height: 25px;
      float: right;
      cursor: pointer;
    }
    .btn {
      float: left;
    }
  }
  .auditprocess_2 {
    margin-top: 10px;
  }
}
.collapseTitle {
  font-weight: bold;
  font-size: 20px;
  color: rgb(103, 194, 58);
}
.cmdElCollapse {
  .collapseTitle {
    color: rgb(64, 158, 255);
  }
}
.collapseTime {
  position: absolute;
  right: 60px;
}
/deep/ .el-collapse-item {
  margin-top: 10px;
}
/deep/ .el-collapse-item__header {
  // border-bottom: 1px solid black;
  position: relative;
  background: #EEF9FF;
}
</style>